package cn.ekuma.epos.bean.util;

import cn.ekuma.epos.businesslogic.RoleUtil;
import cn.ekuma.epos.datalogic.I_DataLogicSystem;
import com.openbravo.bean.AppUser;
import com.openbravo.bean.shard.UserPermission;
import com.openbravo.beans.JPasswordDialog;
import com.openbravo.data.gui.JMessageDialog;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.pos.base.AppLocal;

import javax.swing.*;

public class RoleSwingUtil extends RoleUtil {

    public static boolean hasPermission(javax.swing.JComponent caller, AppUser currentUser, I_DataLogicSystem m_dlSystem, String classname) {
        if (hasPermission(currentUser, classname))
            return true;
        else {
            String advCode = JPasswordDialog.showEditPassword(caller,
                    AppLocal.getIntString("Label.Password"),
                    AppLocal.getIntString("Label.Password"),
                    new ImageIcon(RoleUtil.class.getResource("/com/openbravo/images/password.png")));
            if (advCode != null && fillPermissionsByAdvCode(m_dlSystem, advCode).contains(UserPermission.createPermission(classname))) {//根据特别查找角色并检查相应权限。
                return true;
            }
            JMessageDialog.showMessage(caller, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.notpermissions")));
        }
        return false;
    }

    public static String getLocalePermissionName(String permissionName){
        return AppLocal.getIntString(permissionName);
    }
}